﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using PayrollSystemLibrary.DTO;

namespace PayrollSystemLibrary.Model
{
    public class EmployeeHelper
    {
        public Employee CreateFrom(AddEmployeeInfo info)
        {
            var emp = new Employee();
            emp.Adress = info.Address;
            emp.IsAffiliated = info.IsAffiliated;

            switch (info.Classification)
            {

                case Classification.Hourly:
                    emp.HourlyRate = info.HourlyRate;
                    emp.Classification = "H";
                    emp.PaymentMethod = "H";
                    emp.PaymentSchedule = "W";
                    break;
                case Classification.Unknown:
                    throw new ArgumentOutOfRangeException("info.Classification");
                    break;


            }




            return emp;
        }
        private string TranslateFrom(Classification clasification)
        {
            string value = null;
            switch (clasification)
            {
                case Classification.Hourly:
                    value = "H";
                    break;
                case Classification.Unknown:
                    throw new ArgumentOutOfRangeException("clasification");
                    break;

            }
            return value;
        }

        public ActionResult Validate(Employee employee)
        {
            var resultToList = new List<ValidationResult>();
            var isValid = DataAnnotationsValidator.TryValidate(employee, out resultToList);
            return new ActionResult() { IsValid = isValid, ValidationResult = resultToList };
        }
    }
    public class ActionResult
    {
        public bool IsValid { get; set; }
        public List<ValidationResult> ValidationResult { get; set; }
    }
}
